<template>
    <div class="photoinfo-container">
        <h3> {{ photoinfo.title }} </h3>
        <p class="subtitle">
            <span>发表时间:{{photoinfo.add_time | dateFormat }}</span>
            <span>点击次数:{{ photoinfo.click}}</span>
        </p>
        <hr>
        <!-- 缩略图区域 -->

         <vue-preview :slides="slide1" @close="handleClose"></vue-preview>
        <!-- 图片内容区域 -->
        <div class="content" v-html="photoinfo.content">
            
        </div>
        <cmt-box :id="id"></cmt-box>
    </div>
</template>
<script>
// 导入评论子组件
import comment from '../subcomponents/comment.vue'
export default {
    data(){
        return {
            id:this.$route.params.id,//从路由中获得到图片id
            photoinfo:{},
            slide1: [
            // {
            //     src: 'https://farm6.staticflickr.com/5591/15008867125_68a8ed88cc_b.jpg',
            //     msrc: 'https://farm6.staticflickr.com/5591/15008867125_68a8ed88cc_m.jpg',
            //     alt: 'picture1',
            //     title: 'Image Caption 1',
            //     w: 600,
            //     h: 400
            // },
            // {
            //     src: 'https://farm4.staticflickr.com/3902/14985871946_86abb8c56f_b.jpg',
            //     msrc: 'https://farm4.staticflickr.com/3902/14985871946_86abb8c56f_m.jpg',
            //     // alt: 'picture2',
            //     // title: 'Image Caption 2',
            //     w: 1200,
            //     h: 900
            // }
            ],
            list:[]
        }
    },
    created(){
        this.getPhotoInfo()
        this.getThumbs()
    },
    methods:{
        getPhotoInfo(){
            this.$http.get("api/getimageInfo/"+this.id).then(result => {
                if(result.body.status == 0)
                {
                    this.photoinfo = result.body.message[0]
                }
            })
        },
        handleClose () {
        console.log('close event')
      },
      getThumbs(){
        //   获取缩略图
        this.$http.get('api/getthumimages/'+this.id).then(result => {
            if(result.body.status == 0)
            {
                // 循环每个数组补全宽和高
               result.body.message.forEach(element => {
                   element.w = 600
                   element.h = 400
                   element.msrc = element.src
               });
            //    this.slide1.concat(result.body.message)
                this.slide1 = this.slide1.concat(result.body.message)
            }
        })
      }
    },
    components:{
        'cmt-box':comment
    }
    
}
</script>
<style lang="scss" scoped>
    .photoinfo-container{
        padding: 3px;
        h3{
            color: #26a2ff;
            font-size: 15px;
            text-align: center;
            margin: 15px 0;
        }
        .subtitle{
            display: flex;
            justify-content: space-between;
            font-size: 12px;
        }
        .content{
            line-height: 25px;
            font-size: 13px;
        }

    }
</style>